<html>
<head>
    <script type="text/javascript" src="../libjs/Perl6/MetaModel.js"></script>
    <script type="text/javascript">
        require.INC = "../inc";    
        require('Test.Builder');
        require('Test.More'); 
        
        require.INC = "../libjs";    
        require('Perl6.MetaClass');   
        require('Perl6.Class');                
    </script>         
</head>
<body>
<pre id='test'><script type="text/javascript">

plan({ tests : 25 });

var Foo = new Perl6.Class ('Foo', {
    'class' : {
        'methods' : {
            'bar' : function () { return 'Foo.bar'; },
            'blah' : function (klass, name) { return klass + ".baz(" + name + ")"; }
        }
    }
});
isaOK(Foo, 'Perl6.Class');

isaOK(Foo.meta(), 'Perl6.MetaClass');

ok(Foo.isa('Foo'), '... our class isa Foo');
ok(!Foo.isa('Bar'), '... our class is not a Bar');

ok(Foo.can('bar'), '... Foo can bar()');
ok(!Foo.can('baz'), '... Foo cant baz()');

isaOK(Foo.can('bar'), 'Perl6.Method');
is(call_method(Foo, 'bar'), 'Foo.bar', '... Foo.bar() returns "Foo.bar"');

is(call_method(Foo, 'blah', "Stevan"), 'Perl6.Class=[Foo-0.0.0].baz(Stevan)', '... Foo.baz() takes arguments');

// ...

var Bar = new Perl6.Class ('Bar', { 
    'is' : [ Foo ],
    'class' : {
        'methods' : {
            'foo' : function () { return 'Bar.foo' }
        },
        'multi_methods' : {
            'baz' : [
                [ function (one) { return 'Bar.baz with one arg' },                1 ],
                [ function (one, two) { return 'Bar.baz with two args' },          2 ],               
                [ function (one, two, three) { return 'Bar.baz with three args' }, 3 ],                               
            ]
        }
    }    
});
isaOK(Bar, 'Perl6.Class');

ok(Bar.isa('Bar'), '... our class isa Bar');
ok(Bar.isa('Foo'), '... our class isa Foo');
ok(!Bar.isa('Baz'), '... our class is not a Baz');

ok(Bar.can('foo'), '... Bar can bar()');
ok(Bar.can('bar'), '... Bar can bar()');
ok(Bar.can('baz'), '... Bar can baz()');
ok(!Bar.can('bling'), '... Bar cant bling()');

isaOK(Bar.can('bar'), 'Perl6.Method');
is(call_method(Bar, 'bar'), 'Foo.bar', '... Bar.bar() returns "Foo.bar"');

isaOK(Bar.can('foo'), 'Perl6.Method');
is(call_method(Bar, 'foo'), 'Bar.foo', '... Bar.foo() returns "Bar.foo"');

isaOK(Bar.can('baz'), 'Perl6.MultiMethod');

is(call_method(Bar, 'baz'), 'Bar.baz with one arg', '... Bar.baz() with one arg return correct value');
is(call_method(Bar, 'baz', [ 1 ]), 'Bar.baz with two args', '... Bar.baz() with two args return correct value');
is(call_method(Bar, 'baz', [ 1, 2 ]), 'Bar.baz with three args', '... Bar.baz() with three args return correct value');


</script></pre>
</body>
</html>
